home *** CD-ROM | disk | FTP | other *** search
/ FishMarket 1.0 / FishMarket v1.0.iso / fishies / 001-025 / disk_024 / conquest / conq1.c < prev    next >
C/C++ Source or Header  |  1992-05-06  |  9KB  |  246 lines

  1. #include <stdio.h>
  2. #include "defs.h"
  3. #include "structs.h"
  4. #include "vars.h"
  5.  
  6. boolean
  7. any_bc(team, starnum)
  8. tteam team;
  9. int starnum;
  10. {
  11.         boolean any;  
  12.         int tf_number;
  13.         any = false;
  14.         if ( tf_stars[starnum][team]>0 ) {
  15.                 tf_number = 1;
  16.                 while ( (! any) && (tf_number < 27) ) {
  17.                         any = (tf[team][tf_number].dest==starnum) &&
  18.                             (tf[team][tf_number].eta==0) &&
  19.                             ((tf[team][tf_number].c>0) || 
  20.                                                 (tf[team][tf_number].b>0));
  21.                         tf_number = tf_number +1;
  22.                 };
  23.         };
  24.         return (any);
  25. }
  26.  
  27.  
  28. best_plan(St9rnum, S9ze, T9am)
  29. int *St9rnum, *S9ze;
  30. tteam *T9am;
  31. {
  32.         tplanet *pplanet;
  33.         int starnum, size;
  34.         tteam team;
  35.         team = none;
  36.         starnum = *St9rnum;
  37.         size = 0;
  38.         pplanet = stars[starnum].first_planet;
  39.         while ( pplanet != nil ) {
  40.                 if ( pplanet->capacity > size ) {
  41.                         size = pplanet->capacity;
  42.                         team = pplanet->team;
  43.                 };
  44.                 pplanet=pplanet->next;
  45.         };
  46.         *T9am = team;
  47.         *St9rnum = starnum;
  48.         *S9ze = size;
  49. }
  50.  
  51. check_game_over()
  52. {
  53.         boolean dead[2];
  54.         boolean quit_game;
  55.         int total[2], transports[2], inhabs[2];
  56.         tteam team; 
  57.         int tfnum, starnum; 
  58.         struct stplanet *pplan;
  59.         quit_game = game_over;
  60.         for (team=ENEMY; team <= player; team++) {
  61.                 transports[team] = 0;
  62.                 inhabs[team] = 0;
  63.                 for ( tfnum = 1 ; tfnum<=26; tfnum++ ) {
  64.                         if ( tf[team][tfnum].dest != 0 )
  65.                                 transports[team] = transports[team] 
  66.                                                         + tf[team][tfnum].t;
  67.                 };
  68.         };
  69.         for ( starnum = 1 ; starnum<=nstars; starnum++ ) {
  70.                 pplan = stars[starnum].first_planet;
  71.                 while ( pplan != nil ) {
  72.                         switch ( pplan->team ){
  73.                         case player: 
  74.                                 inhabs[player] = inhabs[player] + pplan->iu;
  75.                                 break;
  76.                         case ENEMY: 
  77.                                 inhabs[ENEMY] = inhabs[ENEMY] + pplan->iu;
  78.                                 break;
  79.                         }; /*switch (*/
  80.                         pplan = pplan->next;
  81.                 };
  82.         };
  83.         for ( team = ENEMY ; team<=player; team++ ) {
  84.                 total[team] = inhabs[team] + transports[team];
  85.                 dead[team] = total[team]==0;
  86.         };
  87.         if (  (! dead[player]) && (! dead[ENEMY]) && (turn >= 40) ) {
  88.                 dead[ENEMY] = total[player] / total[ENEMY] >= 8;
  89.                 dead[player] = total[ENEMY] / total[player] >=8;
  90.         };
  91.         game_over = dead[player] || dead[ENEMY] || (turn>100) ||
  92.             quit_game;
  93.         if ( game_over ) {
  94.                 cle2r_screen();
  95.                 printf("*** Game over ***\n");
  96.                 printf("Player: Population in transports:%3d", 
  97.                                                         transports[player]);
  98.                 printf("  IU's on colonies: %3d  TOTAL: %3d\n", inhabs[player],
  99.                                                         total[player]);
  100.                 putchar('\n');
  101.                 printf("Enemy:  Population in transports:%3d",
  102.                                                         transports[ENEMY]);
  103.                 printf("  IU's on colonies: %3d  TOTAL: %3d\n",
  104.                                                 inhabs[ENEMY], total[ENEMY]);
  105.                 if ( (total[ENEMY] > total[player]) || quit_game  )
  106.                        printf("**** THE ENEMY HAS CONQUERED THE GALAXY ***\n");
  107.                 else if ( (total[player] > total[ENEMY]) )
  108.                    printf("*** PLAYER WINS- YOU HAVE SAVED THE GALAXY! ***\n");
  109.                 else
  110.                         printf("*** DRAWN ***\n");
  111.         };
  112. }
  113.  
  114.  
  115. double fmin();
  116. double exp(), log();
  117.  
  118. display_forces(ennum, plnum, En0dds, Pl0dds, Battl9)
  119. float *En0dds, *Pl0dds;
  120. boolean *Battl9;
  121. {
  122.         float enodds, plodds;
  123.         boolean battle;
  124.         int en_forces, pl_forces;
  125.         zero_tf(ENEMY,ennum);
  126.         zero_tf(player,plnum);
  127.         battle = true;
  128.         if ( tf[ENEMY][ennum].dest != 0 )
  129.                 en_forces = weapons[ENEMY] * ((tf[ENEMY][ennum].c*c_guns)
  130.                                 + (tf[ENEMY][ennum].b*b_guns));
  131.         else
  132.                 battle = false;
  133.         if ( tf[player][plnum].dest !=0 )
  134.                 pl_forces= weapons[player]*((tf[player][plnum].c*c_guns)
  135.                                 + (tf[player][plnum].b*b_guns));
  136.         else
  137.                 battle = false;
  138.         point(50,1);
  139.         if ( tf[ENEMY][ennum].dest != 0 )
  140.                 pr5nt_star(tf[ENEMY][ennum].dest);
  141.         else if ( tf[player][plnum].dest != 0 )
  142.                 pr5nt_star(tf[player][plnum].dest);
  143.         clear_field();
  144.         if ( (en_forces==0) && (pl_forces==0)  ) battle=false;
  145.         if ( battle ) {
  146.                 enodds = ((float)pl_forces) / (en_forces
  147.                                         + tf[ENEMY][ennum].t*t_def 
  148.                                         + tf[ENEMY][ennum].s*s_def);
  149.                 enodds = fmin( 14.0, enodds);
  150.                 enodds = exp((log(0.8)) * enodds);
  151.                 plodds = ((float)en_forces) / (pl_forces
  152.                                         + tf[player][plnum].t*t_def 
  153.                                         + tf[player][plnum].s*s_def);
  154.                 plodds = fmin( 14.0, plodds);
  155.                 plodds = exp( (log(0.8)) * plodds);
  156.                 point(1,19);
  157.                 printf("enemy %5d", en_forces);
  158.                 if ( en_forces > 0 )
  159.                         printf("(weap %2d)", weapons[ENEMY]);
  160.                 else
  161.                         printf("         ");
  162.                 printf("sur: %4.0f", enodds*100.0);
  163.                 point(1,20);
  164.                 printf("player %5d", pl_forces);
  165.                 if ( pl_forces > 0 )
  166.                         printf("(weap %2d)", weapons[player]);
  167.                 else
  168.                         printf("         ");
  169.                 printf("sur: %4.0f", plodds*100.0);
  170.         };
  171.         *En0dds = enodds; 
  172.         *Pl0dds = plodds; 
  173.         *Battl9 = battle;
  174. }
  175.  
  176.  
  177. disp_tf(taskf)
  178. struct sttf *taskf;
  179. {
  180.         if ( taskf->t !=0 ) printf("%2dt", taskf->t);
  181.         else printf("   ");
  182.         if ( taskf->s !=0 ) printf("%2ds", taskf->s);
  183.         else printf("   ");
  184.         if ( taskf->c !=0 ) printf("%2dc", taskf->c);
  185.         else printf("   ");
  186.         if ( taskf->b !=0 ) printf("%2db", taskf->b);
  187.         else printf("   ");
  188. }
  189.  
  190. EN2MY_attack(starnum)
  191. int starnum;
  192. {
  193.         int attack_factors,def_factors;  
  194.         float odds,best_score;
  195.         struct stplanet *pplanet,*best_planet; 
  196.         int en_tf,i;
  197.         boolean first[8];
  198.         for ( i= 1 ; i<=7; i++ )
  199.                 first[i] = true;
  200.         en_tf = 1;
  201.         while ((tf[ENEMY][en_tf].dest!=starnum) || 
  202.                 (tf[ENEMY][en_tf].eta != 0 ) ) en_tf = en_tf + 1;
  203.         do {
  204.                 attack_factors = tf[ENEMY][en_tf].c + 6
  205.                                                 * tf[ENEMY][en_tf].b;
  206.                 best_planet = nil;
  207.                 best_score = 1000;
  208.                 pplanet = stars[starnum].first_planet;
  209.                 while (pplanet != nil ) {
  210.                         if ( (pplanet->team == player) ) {
  211.                                 def_factors =  pplanet->esee_def;
  212.                                 odds = (float)def_factors / attack_factors;
  213.                                 if ( pplanet->capacity > 30 )
  214.                                         odds = (odds - 2) * pplanet->capacity;
  215.                                 else
  216.                                         odds = (odds - 1.5)* pplanet->capacity;
  217.                                 if ( odds < best_score ) {
  218.                                         best_score = odds;
  219.                                         best_planet = pplanet;
  220.                                 };
  221.                         };
  222.                         pplanet = pplanet->next;
  223.                 };
  224.                 if ( best_score < 0 ) {
  225.                         cle3r_left();
  226.                         point(1,19);
  227.                         printf("Enemy attacks: %c%d", starnum+'A'-1, 
  228.                                                         best_planet->number);
  229.                         point(50,1);
  230.                         pr5nt_star(starnum);
  231.                         clear_field();
  232.                         pause();
  233.                         fire_salvo(ENEMY,&tf[ENEMY][en_tf],0,best_planet,
  234.                                         first[best_planet->number]);
  235.                         first[best_planet->number] = false;
  236.                         zero_tf(ENEMY,en_tf);
  237.                         best_planet->esee_def = best_planet->mb + 
  238.                                                         6 * best_planet->amb;
  239.                         pause();
  240.                 };
  241.         } 
  242.         while (best_score < 0 && any_bc(ENEMY, starnum));
  243.         revolt(starnum);
  244. }
  245.  
  246.